package 基础语法;

import java.util.ArrayList;

public class 多态 {
    public static void main(String[] args) {
        final int ass=1;
        //ass=2;//只能赋值一次
        final int[] asa=new int[12];
        asa[0]=1;
        asa[0]=12;//引用类型的地址不可改，内部存储的数据可以改
        //asa=new int[12];
        Person p = new Student();
        p.eat();
        p.drink();
        Student s = (Student) p;
        s.doWord();// 强制类型转换之后可以使用子类的方法？
        System.out.println(s instanceof Student);
        System.out.println(p instanceof Student);
        if(p instanceof Student pn){//jdk7以后
            pn.doWord();//如果p是Student类型，则将其强转，变量名为pn
        }

        try {
            Teacher t = (Teacher) p;
            t.teachClass();
        } catch (Exception e) {
            e.printStackTrace();
        }

        ArrayList a = new ArrayList<>();// Obejct
        a.add(new Person());
        a.add("aaaa");
        a.add(1);
    }
}

class Person {
    public void eat() {
        System.out.println("Person eat");
    }

    public void drink() {
        System.out.println("Person drink");
    }
    public final void pangFlay(){}
}

final class Teacher extends Person {//final  类不允许被继承
    @Override
    public void eat() {
        System.out.println("Teacher eat");
    }
    //@Override public final void pangFlay(){}//不能重写final修饰的 


    public void teachClass() {
        System.out.println("Teacher teachClass");
    }
}

class Student extends Person {
    @Override
    public void eat() {
        System.out.println("Student eat ");
    }

    public void doWord() {// 无法直接调用
        System.out.println("Student doWord");
    }
}
